<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计数器案例</title>
</head>
<body>
    <div id="app">
        <h2>当前计数：{{ counter }}</h2>
        <button v-on:click="add">+</button>
        <button @click="sub">-</button>
    </div>
</body>
<script src="../js/vue.js"></script>
<script>
    // 语法糖：简写 例如：v-on:click == @click
    let app = new Vue({
        el: "#app",
        data: {
            counter: 0
        },
        methods: {
            add:function(){
                if(this.counter >= 10){
                    alert("不能超过10！")
                }else{
                    this.counter++;
                }
            },
            sub:function(){
                if(this.counter <= 0){
                    alert("不能小于0！")
                }else{
                    this.counter--;
                }
            }
        }
    });
</script>
</html>